package com.lq.controller;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.validation.Valid;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.lq.pojo.DemoDto;
import com.lq.pojo.DemoOutputDto;
import com.lq.pojo.FFResponseModel;
import com.lq.pojo.User;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
/**
 * @Api:用在类上，说明该类的作用
 * @ApiOperation：注解来给API增加方法说明。
 * @ApiImplicitParam：用来注解来给方法入参增加说明。
 * @author huaxin
 *
 */
@RestController
@RequestMapping(value = "/say")
@Api(value = "Test一个用来测试swagger注解的控制器")
public class TestController {
	
	@RequestMapping(value = "/getUserName",method = RequestMethod.GET)
	@ApiOperation(value = "根据用户编号获取用户姓名",notes = "test:仅1和2有正确返回")
	@ApiImplicitParam(paramType = "query",name = "userNumber",value = "用户编号",required = true,dataType = "Integer")
	public String getUserName(@RequestParam Integer userNumber) {
		if(userNumber==1) {
			return "张三烦";
		}else if(userNumber==2) {
			return "慕容熙";
		}else {
			return "未知";
		}
	}
	
	
	@RequestMapping("/updatePassword")
	@ApiOperation(value = "修改用户密码",notes = "根据用户id修改密码")
	@ApiImplicitParams({
		 @ApiImplicitParam(paramType="query", name = "userId", value = "用户ID", required = true, dataType = "Integer"),
	     @ApiImplicitParam(paramType="query", name = "password", value = "旧密码", required = true, dataType = "String"),
	     @ApiImplicitParam(paramType="query", name = "newPassword", value = "新密码", required = true, dataType = "String")
	})
	public String updatePassword(@RequestParam(value="userId") Integer userId, @RequestParam(value="password") String password, 
            @RequestParam(value="newPassword") String newPassword){
      if(userId <= 0 || userId > 2){
          return "未知的用户";
      }
      if(StringUtils.isEmpty(password) || StringUtils.isEmpty(newPassword)){
          return "密码不能为空";
      }
      if(password.equals(newPassword)){
          return "新旧密码不能相同";
      }
      return "密码修改成功!";
    } 
	
	
	
	@RequestMapping("/code")
	@ApiOperation(value = "post请求调用")
	public FFResponseModel<DemoOutputDto>invokePost(@ApiParam(name = "传入对象",value = "传入json格式",required = true) @RequestBody @Valid DemoDto input){
		return new FFResponseModel<DemoOutputDto>("成功","执行该方法返回消息为成功");
	}
	
}
